package com.zheng.russiaRec.model 
{
	import flash.geom.Point;
	
	/**
	 * @describe  	活动积木
	 * @author  	Mr.zheng
	 * @website 	http://blog.sina.com.cn/zihua2007
	 * @time		... 
	 */
	public class P_LiveGroup
	{
		//中心点坐标
		public var cp:Point;
		//棋盘中的坐标
		public var sx:int;
		public var sy:int;
		public var _liveToGroup:Array;
		//====================================================
		private var _data:Array;
		//方向
		private var _dir:int;
		//data总数
		private var _dataTotalNum:int;
		/**
		 * T字积木
		 *  □■□
		 * 	  □
		 */ 
		private var _groupArr0:Array=[[[0, 1], [1, 1], [2, 1], [1, 0]],
									[[1, 1], [1, 0], [1, 2], [2, 1]],
									[[0, 1], [1, 1], [2, 1], [1, 2]],
									[[1, 1], [1, 0], [1, 2], [0, 1]]];
		/**
		 * Z字积木
		 *  □■
		 * 	  □□
		 */ 
		private var _groupArr1:Array=[[[0, 0], [1, 0], [1, 1], [2, 1]],
									[[0, 0], [0, 1], [1, 0], [1, -1]]];
		private var _groupArr2:Array=[[[1, 0], [2, 0], [0, 1], [1, 1]],
									[[0, 0], [0, 1], [1, 1], [1, 2]]];
		/**
		 * 一字积木
		 *  □□■□
		 */ 
		private var _groupArr3:Array=[[[0, 0], [1, 0], [2, 0], [3, 0]],
									[[2,-2],[2,-1],[2,0],[2,1]]];
		/**
		 * 7字积木
		 *  □□■
		 * 	    □
		 */ 
		private var _groupArr4:Array=[[[0, 0], [1, 0], [2, 0], [2, 1]],
									[[1,0],[1,1],[1,2],[0,2]],
									[[0,0],[0,1],[1,1],[2,1]],
									[[0,0],[1,0],[0,1],[0,2]]];
		private var _groupArr5:Array=[[[2,0],[0,1],[1,1],[2,1]],
									[[0,0],[0,1],[0,2],[1,2]],
									[[0,0],[1,0],[2,0],[0,1]],
									[[0,0],[1,0],[1,1],[1,2]]];
		/**
		 * 田字积木
		 *  □□
		 * 	□□   
		 */ 
		private var _groupArr6:Array=[[[0, 0], [1, 1], [1, 0], [0, 1]]];
		
		public function P_LiveGroup()
		{
			init();
		}
		
		private function init():void
		{
			cp = new Point(1, 1);
			_liveToGroup=new Array();
			sx = 3;
			sy = 0;
			_dir = 0;
			_dataTotalNum=7;
		}
		public function get liveGroupData():Array{
			var num:int=rand(0,_dataTotalNum-1);
			_data=this["_groupArr"+num];
			return liveGridGroup;
		}
		public function set liveGridGroup(value:Array):void{
			_liveToGroup=value;
		}
		public function get liveGridGroup():Array 
		{
			var dataCopy:Array =_data[_dir].concat();
			var itemCopy:Array=[];
			var temp:Array=[];
			for (var name:String in dataCopy) 
			{
				itemCopy=dataCopy[name].concat();
				itemCopy[0] =int(itemCopy[0])+sx;
				itemCopy[1] =int(itemCopy[1])+sy;
				temp.push(itemCopy);
			}
			return temp;
		}
		
		public function get liveToGroup():Array{return _liveToGroup};
		public function set liveToGroup(value:Array):void{
			_liveToGroup=value;
		}
		
		public function get dir():int{return _dir};
		public function set dir(value:int):void{
			if(value>=_data.length){
				value=0;
			}
			if(value<0){
				value=_data.length-1;
			}
			_dir=value;
			
		}
		public function get rotationData():Array {
			dir++;
			return liveGridGroup;
		}
		/**
		 * 获取随机值
		 * @param	min
		 * @param	max
		 * @return
		 */
		private function rand(min:int,max:int):int{
			return Math.random()*(max+1)-min;
		}
	}
	
}